'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	
	const db = uniCloud.database();
	const collection = await db.collection('user_info');
	
	let res2 = await new Promise((resolve, reject)=>{
		let res1 = collection.where({
			"_id":event.id,
		}).update({
			gold: event.gold
		});
		 
		res1.then(async (y)=>{
			console.log('y : ', JSON.stringify(y))
			
			if(y.updated == 0){
				resolve({
					code:1,
					data: {
						id: event.id,
						gold:event.gold
					}
				})
			}else{
				reject({"msg":'error'});
			}
		})
		
		res1.catch((n)=>{
			reject({"msg":'error'});
		})
	})
	
	//返回数据给客户端
	return res2
};
